<html>
<head>
	<title>Image</title>
	<script type="text/javascript" src="../prototype.js" ></script>
</head>
<body>
	<form>
	<table class="formTable" width="100%">
		<tr>
			<td class="formTitle">Image Src</td>
			<td><input type="text" id="ImageUrl" name="ImageUrl" style="width:300px" /></td>
		</tr>
		<tr>
			<td class="formTitle">Size</td>
			<td>
				<input type="text" id="Width" name="Width" style="width:50px" /> x <input type="text" id="Height" name="Height" style="width:50px" />
			</td>
		</tr>
		<tr>
			<td class="formTitle">Alt</td>
			<td><input type="text" id="Alt" name="Alt" style="width:300px"  /></td>
		</tr>
	</table>
	
	<input type="submit" id="SubmitImage" value="Insert Image" /> 
	</form>
	

<script type="text/javascript">	

Event.observe(window,'load',init);
Event.observe($('SubmitImage'),'click',submitImage);
Event.observe(document.getElementsByTagName('form')[0],'submit',submitImage);

var ftb;
var refresh

function init() {
	if (window.opener)
		refresh = window.opener.Refresh;
	else
		refresh = window.parent.Refresh;
	
	ftb = refresh.Web.CurrentFreeTextBox;
	if (ftb == null) ftb = refresh.Web.FreeTextBoxList[0];
	
	var img = ftb.getNearest('img');
	var imgSrc = '';
	if (img) {
		var imgSrc = img.getAttribute('temp_src');
		if (!imgSrc) imgSrc = img.getAttribute('src');
		
		$('ImageUrl').value = (imgSrc != '') ? imgSrc : 'http://';
		
		$('Width').value = img.width;
		$('Height').value = img.height;
		$('Alt').value = img.alt;
	}
	
	
}
function submitImage(event) {
	Event.stop(event);
	
	var imgSrc = $F('ImageUrl');
	var width = $F('Width');
	var height = $F('Height');
	var alt = $F('Alt');
	
	if (imgSrc == '') 
		return false;
	
	ftb.insertImage(imgSrc,width,height,alt); 
	
	refresh.Web.ModalWindow.hide();
	window.close();
}
</script>
</body>
</html>